package com.taplinker.client.crm.adapter;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.RadioButton;

import com.taplinker.client.R;
import com.taplinker.dto.web.CrmCategoryProto.Category;

public class AppCategoryAdapter extends BaseAdapter {

	private List<Category> datas;
	private Context mContext;
	private int mposion = -1;
	public AppCategoryAdapter(List<Category> datas,Context context) {
		this.datas = datas;
		mContext = context;
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return datas.size();
	}

	@Override
	public Object getItem(int arg0) {
		// TODO Auto-generated method stub
		return datas.get(arg0);
	}

	@Override
	public long getItemId(int arg0) {
		// TODO Auto-generated method stub
		return arg0;
	}

	@Override
	public View getView(int position, View contentView, ViewGroup arg2) {
		
		Holder holder = null;
		if(contentView==null){
			holder = new Holder();
			contentView = LayoutInflater.from(mContext).inflate(R.layout.lv_item_appcategory, null);
			holder.button = (RadioButton)contentView.findViewById(R.id.rb);
			contentView.setTag(holder);
		}else{
			holder = (Holder) contentView.getTag();
		}
		holder.button.setChecked(mposion==position?true:false);
		holder.button.setText(datas.get(position).getName());
		return contentView;
	}

	public void setCheckedPosition(int posion){
		this.mposion = posion;
	}
	public int getCheckedPosition(){
		return mposion;
	}
	class Holder {
		RadioButton button;
	}
}
